package com.py.gs.businese.chatcheck;

import java.util.HashMap;

public class ChatCheckTest {
	
	static ChatCheckTools1 checkTools1 = new ChatCheckTools1();
	static ChatCheckTools2 checkTools2 = new ChatCheckTools2();

	public static void main(String[] args) {
//		String chatPre = "啊吧才的额飞个好发让加叫接块开快了咯来哦噢喔平跑怕拍一要有用你那哪被不表从想先新";
		String chatPre = "烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟";
		String chatCur = "烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟烟哪被不表从想用你那哪被不表从先新新新新烟";
//		String chatCur = "中的复重有 没段一是这";
//		System.out.println(chatCur.length());
//		System.out.println(checkTools1.checkSimilarity(chatCur, chatPre));
//		System.out.println(checkTools2.checkSimilarity(chatCur, chatPre));
//		System.out.println(checkSimilarity1(chatCur, chatPre));
//		System.out.println(checkSimilarity2(chatCur, chatPre));
//		System.out.println(similarity(chatCur, chatPre));
		int count = 0;
//		double dCount = 0;
		long a = System.currentTimeMillis();
		for (int i = 0; i < 10000000; i++) {
			boolean isRepet = checkTools1.checkSimilarity(chatCur, chatPre);
//			boolean isRepet = checkTools2.checkSimilarity(chatCur, chatPre);
//			boolean isRepet = StringSimilarityTools.similarity(chatCur, chatPre) > 0.5;
//			boolean isRepet = checkSimilarity1(chatCur, chatPre);
//			boolean isRepet = checkSimilarity2(chatCur, chatPre);
			if (isRepet) {
				count++;
			}
//			dCount += similarity(chatCur, chatPre);
		}
		long b = System.currentTimeMillis();
		System.out.println(b - a);
//		System.out.println(chatCur.length());
//		System.out.println(check(chatCur, chatPre));
		System.out.println(count);
//		System.out.println(dCount);
	}
	public static boolean checkSimilarity1(String checkStr, String sourceStr) {
		if (checkStr.length() < 10 || sourceStr.length() < 10) {
			return false;
		}
		int matchCount = 0;
		for (int i = 0; i < checkStr.length(); i++) {
			if (sourceStr.indexOf(checkStr.charAt(i)) >= 0) {
				matchCount++;
			}
		}
		return matchCount > checkStr.length() / 2;
	}
	public static boolean checkSimilarity2(String checkStr, String sourceStr) {
		if (checkStr.length() < 10 || sourceStr.length() < 10) {
			return false;
		}
		HashMap<Character, Boolean> map = new HashMap<>(sourceStr.length());
		for (int i = 0; i < sourceStr.length(); i++) {
			map.put(sourceStr.charAt(i), true);
		}
		int matchCount = 0;
		for (int i = 0; i < checkStr.length(); i++) {
			Boolean repet = map.get(checkStr.charAt(i));
			if (repet != null && repet) {
				matchCount++;
			}
		}
		return matchCount > checkStr.length() / 2;
	}

}
